#include <stdio.h>
#include <bitset>

int main()
{
    unsigned int a, b, c, s;
    while (scanf("%d %d %d %d", &a, &b, &c, &s) == 4 && a > 0)
    {
        unsigned short zero_bits = 0xFFFF, one_bits = 0xFFFF;
        std::bitset<65536> seen;
        do
        {
            zero_bits &= ~s;
            one_bits &= s;
            seen.set(s);
            s = (a * s + b) % c;
        } while (!seen.test(s) && (zero_bits || one_bits));

        char s[50];
        for (int i = 15; i >= 0; i--)
        {
            s[15-i] = (zero_bits & (1<<i))? '0' :
                      (one_bits & (1<<i))? '1' : '?';
        }
        s[16] = '\n';
        s[17] = '\0';
        fputs(s, stdout);
    }
    return 0;
}
